package demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import service.UserService;

@Controller
public class UserController {
    /*@Autowired//1.属性注入（更加简单的从Spring容器中读取到对象）
    private UserService userService;*/
    //2.setter注入
/*    private UserService userService;
@Autowired//Spring会将对象给方法中
    public void setUserService(UserService userService) {
        this.userService = userService;
    }*/
    //3.构造方法注入
    private UserService userService;
    @Autowired//如果这个类中只有这一个构造方法，可以不加Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void test() {
        System.out.println("UserController：hello");
        userService.test1();
    }
}
